#include "syralink.hpp"
#include "loger.hpp"
#include <iostream>
sl::PreMainInitializer::PreMainInitializer()
{
    sl::loger::__detail::init();

    std::ios::sync_with_stdio(false);
}

sl::PreMainInitializer::~PreMainInitializer() { }

// 创建全局对象实例
static sl::PreMainInitializer g_initializer;

void sl::print(const std::vector<byte>& data)
{
    std::cout << "========= print: " << std::dec << data.size() << " bytes "
              << " =========" << std::endl;
    for(size_t i = 0; i < data.size(); ++i) {
        if(i > 0 && i % 16 == 0) {
            std::cout << std::endl;
        }
        std::cout << std::hex << std::setfill('0') << std::setw(2)
                  << static_cast<int>(data[i]) << " ";
    }
    std::cout << std::endl;
}

std::string sl::hex_dump(const std::vector<byte>& data)
{
    std::ostringstream oss;
    for(size_t i = 0; i < data.size(); ++i) {
        if(i > 0 && i % 16 == 0) {
            oss << " | ";
        }
        oss << std::hex << std::setfill('0') << std::setw(2)
            << static_cast<int>(data[i]) << " ";
    }

    return oss.str();
}
